﻿using ExcelDna.Integration;
using ExcelDna.Integration.CustomUI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExcelPlugin
{
    [ComVisible(true)]
    public class Main : ExcelRibbon, IExcelAddIn 
    {
        #region 插件初始化
        public void AutoOpen() {
            OperationUtil.AddInInit();
        }

        public void AutoClose() {
        }
        #endregion

        #region 按钮回调
        public void OnGotoSubSheet(IRibbonControl control) {
            onGotoSubSheet();
        }

        public void OnBackRefer(IRibbonControl control) {
            onBackRefer();
        }

        public void OnForwardRefer(IRibbonControl control) {
            onForwardRefer();
        }

        public void OnFindID(IRibbonControl control) {
            onFind(); 
        }
        public void OnReloadXml(IRibbonControl control) {
            onReloadXml();
        }
        public void OnBatchChangeHeadName(IRibbonControl control) {
            onBatchChangeTableHead();
        }
        public void OnCheckDefine(IRibbonControl control) {
            onCheckDefine();
        }
        public void OnXmlTemplate(IRibbonControl control) {
            onXmlTemplate();
        }
        #endregion

        #region 实际操作函数，可绑定快捷键
        public static void onSave() {
            //删除空行
            MsgHelper.PopInformationMsg("Saved");
        }
        public static void onFind() {
            OperationUtil.FindIdDefine();
        }
        public static void onGotoSubSheet() {
            OperationUtil.GotoSubSheet();
        }
        public static void onBackRefer() {
            OperationUtil.BackReferCell();
        }
        public static void onForwardRefer() {
            OperationUtil.ForwardReferCell();
        }
        public static void onReloadXml() {
            MsgHelper.PopQueryMsg("确认重新导入吗？", () =>
            {
                XmlLoader.ReloadXmlConfigs();
            });
        }
        public static void onBatchChangeTableHead() {
            OperationUtil.ChangeTableHead();
        }
        public static void onCheckDefine() {
            OperationUtil.ShowDefineFileNames();
        }
        public static void onXmlTemplate() {
            OperationUtil.GenerateXmlTemplate(); 
        }
        #endregion


    }

}
